<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客列表</title>
    <link rel="stylesheet" href="css/conmmon.css">
    <link rel="stylesheet" href="css/blog_list.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/logout.js"></script>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/log.jpg" alt="">
        <span class="title">我的博客系统</span>
        <!-- 用来占据中间位置 -->
        <span class="spacer"></span>
        <a href="blog_list.html">主页</a>
        <a href="blog_add.html">写博客</a>
        <a href="javascript:logout()">注销</a>
    </div>
    <!-- 版心 -->
    <div class="container">
        <!-- 左侧个人信息 -->
        <div class="container-left">
            <div class="card">
                <img src="img/avatar.png" class="avtar" alt="">
                <h3 id="article"></h3>
                <a href="http:www.github.com">github 地址</a>
                <div class="counter">
                    <span>文章</span>
                </div>
                <div class="counter" >
                    <span id="num"></span>
                </div>
            </div>
        </div>
        <!-- 右侧内容详情 -->
        <div class="container-right" id="blogDiv">

<!--            &lt;!&ndash; 每一篇博客包含标题, 摘要, 时间 &ndash;&gt;-->
<!--            <div class="blog">-->
<!--                <div class="title">我的第一篇博客</div>-->
<!--                <div class="date"> <span>2021-06-02</span> &nbsp;&nbsp;<span>作者</span></div>-->
<!--                <div class="desc">-->
<!--                    从今天起, 我要认真敲代码. Lorem ipsum, dolor sit amet consectetur adipisicing elit. Cum distinctio ullam eum ut-->
<!--                    veroab laborum numquam tenetur est in dolorum a sint, assumenda adipisci similique quaerat vel.-->
<!--                    Facere,-->
<!--                    et.-->
<!--                </div>-->
<!--                <div class="san">-->
<!--                     <a href="blog_content.html?id=1" class="detail">查看全文 &gt;&gt;</a>&nbsp;&nbsp;-->
<!--                     <a href="blog_content.html?id=1" class="detail">修改 &gt;&gt;</a>&nbsp;&nbsp;-->
<!--                     <a href="blog_content.html?id=1" class="detail">删除 &gt;&gt;</a>-->
<!--                </div>-->
<!--               -->
<!--            </div>-->
        </div>
    </div>

    <script>
        function init(){
            $.post("user/check",{},function (res){
                if(res.code==200 && res.data!=null){
                    var artile=res.data.username;
                    document.getElementById("article").innerHTML=artile;
                }else{
                    alert("抱歉，操作失败"+res.msg);
                    location.href="login.html";
                }
            })


            $.get("/art/mylist",{},
            function (res){
                if(res.code==200){
                    var createHtml="";
                    var artlist=res.data;
                    if(artlist==null || artlist.length==0){
                        //没有文章。
                        createHtml+="<h3>加油写文章</h3>";
                    }else{
                        document.getElementById("num").innerHTML=artlist.length;
                        for(var i=0;i<artlist.length;i++){
                            var art=artlist[i];
                            createHtml+='<div class="blog">';
                            createHtml+='<div class="title">'+art.title+'</div>';
                            createHtml+='<div class="date">';
                            createHtml+='<span>'+art.createtime+'</span>';
                            createHtml+='&nbsp;&nbsp;';
                            createHtml+='<span>'+art.name+'</span>';
                            createHtml+='</div>';
                            createHtml+='<div class="desc">'+art.content+'</div>';
                            createHtml+='<div class="san">';
                            createHtml+='<a href=blog_content.html?id='+art.articleId+' class="detail">查看全文>></a>';
                            createHtml+='<a href=blog_edit.html?id='+art.articleId+' class="detail">修改>></a>';
                            createHtml+='<a href=javascript:del('+art.articleId+') class="detail">删除>></a>';
                            createHtml+='</div></div>';
                        }
                    }
                    jQuery("#blogDiv").html(createHtml);
                }else{
                    alert("抱歉，操作失败"+res.msg);
                    location.href="login.html";
                }
            })
        }
    init();
        function del(aid){
            if(aid=="" || aid<=0){
                alert("参数错误！");
                return false;
            }
            $.post("/art/delete",{
                "aid":aid
            },function (res){
                if (res.code==200 && res.data==1){
                    alert("删除成功");
                    location.href=location.href;
                }else{
                    alert("删除失败！"+res.msg);
                }
            })
        }
    </script>



</body>

</html>